Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if stock_item exists before adding variant to stock_location #72

Open
wants to merge 1 commit into
base: 2-4-stable
Choose a base branch
from

Conversation

yf6
Copy link

@yf6 yf6 commented Oct 22, 2015

The only different between propagate_variant and set_up_stock_item is that set_up_stock_item checks if a stock_item exist for this variant at this location before creating a new one. This has proven to be useful in various occasions for me - when setting up test objects, or when we set up the suppliers/products slightly differently. Without the check, if some how the stock_item already exists, rails gives a validation error like: Variant already exists.

I've only tested it in 2-4, but doesn't seem to me this part of the code has changed much from 2-3 to 3-0, so probably safe to apply this to all of those branches.

@@ -24,7 +24,7 @@ def populate_for_supplier!(supplier)
variants_including_master.each do |variant|
unless variant.suppliers.pluck(:id).include?(supplier.id)
variant.suppliers << supplier
supplier.stock_locations.each { |location| location.propagate_variant(variant) }
supplier.stock_locations.each { |location| location.set_up_stock_item(variant) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [88/80]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants